<?php
//$_REQUEST['athloncode']="circledesign";
include_once("model/common.php");
include_once("../../config.php");


include_once("../../../config/site_theme_config.php");






foreach($_unit as $k=>$v)

{


    echo $k;
    echo "<br/>";

    $_REQUEST['athloncode']=$k;

    $_code=$k;
    $_date=date("Y-m-d");


    error_reporting(E_ERROR);
    define('CURSCRIPT', 'forumdisplay');


    $dbHostname = "127.0.0.1";     //数据库地址，有ip必须用ip，会快很多
    $dbUsername = "root";          //数据库用户名
    $dbPassword = "98154981";     //数据库密码
    $dbName     = $_unit[$_REQUEST['athloncode']]['database'];



    global $table_Prefix;
    global $table_prefix;
    $table_Prefix="athlon_";         //该工程的table前缀，后期请不要再使用首字母大写
    $table_prefix="athlon_";         //该工程的table前缀,后期请统一使用全小写



    $dblink = MYSQL_CONNECT($dbHostname, $dbUsername, $dbPassword) or die("数据库:".$dbName."连接失败!");
    mysql_select_db($dbName) or die("Connection链接数据库失败【" . $dbName."】");
    mysql_query("set names utf8");




//这里要循环不同的数据库，去查找不同的数据库的信息，再推送出去
//一旦用户比较多的时候，这个循环就未必能够应付得来，一次访问30秒运行，发送出这么多数量的信息模板。
//所以必须要有一个平台管理数据库，用于记录推送信息，分开时段发送这些信息模板。
//同时自动登录的时候，也要类似饭堂一样，有个表格专门记录自动登录的时候，微信用户所属的公司信息。





//获取设置表格的数据，判断哪些人要接收周报
    $setting=select_one_line_all_items($table_prefix."setting","nid > 0");


    //把week_report_manager的标签拆成sql语句
    $now_week_report_manager_str=str_replace(",","','",$setting['week_report_manager']);





    //员工 未做数据筛选。全部都显示
    $employee_list = select_lines_all_items($table_Prefix . "employee", "nid desc", " nid in ('".$now_week_report_manager_str."') and openid is not null and openid != ''", "");

    $openid_list=transform_2darray_in_1darray_with_new_key($employee_list,"nid","openid");


    print_r2($openid_list);





if($openid_list){
    //循环发送本系统接收周报的openid
    foreach($openid_list as $k=>$v)
    {

       //发送消息模板的地址
        $url = "http://yitong.zhihuitiangong.com/api/wechat_mp/send_message_model.php";



        $post_data = array(
            "touser"=>$v, //推送给谁,openid
            //"touser"=>'oUaqG0dZdR4ITehiwDOLoCxcn49w', //推送给工作号
            "template_id"=>"1DqGzhxUzmy-qr6FXIbYjYoRAF8WAQV9t2WuKzn0B5w", //微信后台的模板信息id
            //http://t.yitong.com/front/employee_center/view/report_week.php?athloncode=circledesign&date=2023-07-10
            "url"=>"http://".$host."/front/employee_center/view/report_week.php?athloncode=".$_code."&date=".$_date,
            "data"=> array(
                "first" => array(
                    "value"=>"【天宫】已经为您生成本周系统统计周报",
                    "color"=>"#173177"
                ),
                "keyword1"=>array(
                    "value"=>date("Y-m-d"),//时间
                    "color"=>"#173177"
                ),

                "keyword2"=>array(
                    "value"=>"周报创建通知",
                    "color"=>"#173177"
                ),
                "remark"=> array(
                    "value"=>"请点击本通知跳转到【天宫系统】页面查看详情；",
                    "color"=>"#173177"
                ),
            )
        );

        $sql_data = serialize($post_data);
        echo $data['content'] = $sql_data;
        $re_back = send_wx_sms($url , $data);
        $re_back_arr = json_decode($re_back, true);

        echo $re_back;
    }

    echo "<br/>";
    echo "runs end";
    echo "<br/>";
    echo "<br/>";
    echo "<br/>";
    echo "<br/>";
    echo "<br/>";
}





}














?>

